/*
 * AbstractInstance.java
 *
 * Created on July 9, 2007, 6:00 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */
package nlpeap.ml;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

/**
 *
 * @author versley, modified by chuter
 */
public abstract class AbstractInstance implements Instance {
   
   protected Map<FeatureDescription,Object> _featureVals;
   
   public AbstractInstance()
   { _featureVals=new HashMap<FeatureDescription,Object>(); }
   
    public <T> T getFeature(FeatureDescription<T> descr)
    { return (T)_featureVals.get(descr); }
    
    public <T> void setFeature(FeatureDescription<T> descr, T value)
    { _featureVals.put(descr,value); }
    
    public String getDebugInfo() {
        return "";
    }
    
    public void clearFeatureValues() {
    	_featureVals.clear();
    }
    
    public String allFeatures() {
    	StringBuffer fe_bug = new StringBuffer();
    	
    	Iterator it = _featureVals.entrySet().iterator();
    	while (it.hasNext()) {
    		Entry entry = (Entry) it.next();
    		FeatureDescription fe = (FeatureDescription) entry.getKey();
    		Object fe_value =  entry.getValue();
    		fe_bug.append(fe.getFEname()).append(":").
    		append(fe_value.toString()).append(" ");
    	}
    	
    	return fe_bug.toString();
    }
}
